package com.jyhs.maven.serlvet;



import com.alibaba.fastjson.JSON;
import com.jyhs.maven.Serice.impl.xtyhSericeImpl;
import com.jyhs.maven.Serice.xtyhSerice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;

import java.util.Map;

@WebServlet(urlPatterns = "/ucx")
public class Ucx extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        xtyhSerice xt = new xtyhSericeImpl();
        String payname = req.getParameter("payname");
        String coname = req.getParameter("coname");
        if (payname == null || payname.equals("")) {
            payname = "%";
        }
        if (coname == null || coname.equals("")) {
            coname="%";
        }
        try {
            Map<String,Object> map=new HashMap<>();
            map.put("nums",xt.updateXtyhDao(payname,coname));
            map.put("data",xt.getZzjlDao(payname,coname,Integer.parseInt(req.getParameter("page")), Integer.parseInt(req.getParameter("limit"))));
            PrintWriter ou = resp.getWriter();
            ou.print(JSON.toJSONString(map));
            ou.flush();
            ou.close();
        } catch (SQLException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
